import java.awt.*;
import java.awt.geom.Ellipse2D;

public class Ball extends Ellipse2D.Double {
    float x, y, lastX, lastY;
    int width, height;
    float xVelocity, yVelocity;
    float speed;
    int radius;
    boolean heatActive;
    float velocityConstant;
    float heatTimer;
    Dimension border;
    private GameController logic;

    public Ball(Dimension border) {
        this.border = border;
        logic = GameController.getInstance();

        heatTimer = 0;
        velocityConstant = 1.0f;
        width = 30;
        height = 30;
        radius = width / 2;
        lastX = x;
        lastY = y;
        xVelocity = speed;
        yVelocity = speed;
        setFrame(x - width / 2, y - height / 2, width, height);

    }

    public void update(double delta) {
        if(heatTimer > 0) {
            heatActive = false;
            heatTimer -= delta;
        }
        setFrame(x - width / 2, y - height / 2, width, height);
        //lastX = x;
        //lastY = y;

        x += xVelocity * delta;
        y += yVelocity * delta;

        if (x + width / 2 >= border.getSize().getWidth()) {

            xVelocity *= -1;
            x = (float) border.getWidth() - width / 2;
            //yVelocity = yVelocity * 0.95f; // Decrease speed by %5
        } else if (x - width / 2 <= 0) {
            xVelocity *= -1;
            x = width / 2;
        }

        if (y + height / 2 >= border.getSize().getHeight()) {
            // Ball goes down don't struck to below
            /*
            yVelocity *= -1;
            y = (float) border.getHeight() - height/2;
            */
            //xVelocity = xVelocity * 0.95f; // Decrease speed by %5
        } else if (y - height / 2 <= 0) {
            System.out.println(y);
            System.out.println(height / 2);
            yVelocity *= -1;
            y = height / 2;
        }
    }

    public void applyEffect(String type) {
        switch (type) {
            case "slowerBall":
                velocityConstant *= 1.2f;
                break;
            case "fasterBall":
                velocityConstant *= 0.8f;
                break;
            case "heatBall":
                heatTimer = 200;
                heatActive = true;
                break;
            default:
                break;
        }
    }
}
